package com.clickpaas.workinghours.dao.Impl;

import com.bizcloud.ipaas.tbba4bf83484b4ed2aacba581fbfeac4d.  d20210220155135.codegen.*;
import com.bizcloud.ipaas.tbba4bf83484b4ed2aacba581fbfeac4d.  d20210220155135.model.*;
import com.clickpaas.workinghours.bean.WorkingHoursDTOBean;
import com.clickpaas.workinghours.dao.TimeSheetDao;
import com.clickpaas.workinghours.entity.TimeSheetEntity;
import com.clickpaas.workinghours.utils.SpringUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Repository;
import javax.annotation.Resource;
import java.util.List;


@Slf4j
@Repository
public class TimeSheetDaoImpl implements TimeSheetDao {

    @Resource
    private WorkingHoursDTOBean dtoBean;
    @Resource
    private TimesheetApi timesheetApi;
    /**
     * 根据条件查询
     *
     * @param timeSheetDTO
     */
    private List<TimeSheetDTOResponse> getDataByCondtion(TimeSheetDTO timeSheetDTO) {
        DataResponseListTimeSheetDTO dataInfo = timesheetApi.findTimeSheetUsingPOST(timeSheetDTO);
        if(null == dataInfo
                || null == dataInfo.getData()
                || dataInfo.getData().size()<=0
                || !"SUCCESS".equals(dataInfo.getMessage())){
            log.info("当前查询的数据：【{}】",dataInfo);
            return null;
        }
        return dataInfo.getData();
    }

    /**
     * 根据条件查询项目对象数据
     *
     * @param entity
     */
    @Override
    public List<TimeSheetDTOResponse> queryDataInfo(TimeSheetEntity entity) {
        TimeSheetDTO tTimeSheetDTO1 = dtoBean.timeSheetDTO();
        try {
            SpringUtil.copyPropertiesIgnoreNull(entity,tTimeSheetDTO1);
        }catch (Exception e){
            log.info("对象转换失败！转换的对象是：【{}】",entity);
        }
        return getDataByCondtion(tTimeSheetDTO1);
    }

}
